package com.huaguoguo.cyg.spider.downloader;

import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.downloader.PhantomJSDownloader;

/**
 * 类说明： <br/>
 * author:huaguoguo
 * Date: 2019/8/18
 * Time: 3:10
 */
public class FixPhantonJSDownloader extends PhantomJSDownloader {

    @Override
    protected String getPage(Request request) {
        //设置必要参数
        DesiredCapabilities dcaps = new DesiredCapabilities();
        //ssl证书支持
        dcaps.setCapability("acceptSslCerts", true);
        //截屏支持
        dcaps.setCapability("takesScreenshot", false);
        //css搜索支持
        dcaps.setCapability("cssSelectorsEnabled", true);
        //js支持
        dcaps.setJavascriptEnabled(true);
        //驱动支持
        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,"D:\\dev\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");

        PhantomJSDriver driver = new PhantomJSDriver(dcaps);
        driver.get(request.getUrl());
        return driver.getPageSource();
    }
}
